package com.panghl.controller;

import com.panghl.service.EmailService;
import com.panghl.utils.RandomUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author panghl
 * @Date 2021/2/3 16:51
 * @Description 登录注册发送邮件
 **/
@RestController
@RequestMapping("email")
public class EmailController {

    @Autowired
    private EmailService emailService;

    @PostMapping("/{sendTo}")
    public String sendEmail(@PathVariable("sendTo") String sendTo) {
        String code = RandomUtil.getSixBitRandom();
        Map<String, Object> map = new HashMap<>();
        map.put("code", code);
        boolean isSuccess = emailService.sendCodeByEmail(map, sendTo);
        return isSuccess ? "SUCCESS!!":"FAIL!!";
    }

}
